// 时机: 在 Jest 环境设置之后运行，即在每次测试运行之前。
// 用途: 适用于配置和初始化 Jest 环境之后需要的全局设置，例如引入测试库（testing library 等）所提供的工具函数。

jest.mock("@teld/api-proxy/src/utils/common.js", () => ({
  getServiceUrl: jest.fn((param) => {
    return param;
  }),
}));
jest.mock("@teld/api-proxy/src/utils/url.js", () => ({
  getQueryString: jest.fn((name, url) => {
    var reg = new RegExp(name + "=([^&]*)", "i");

    var r = url.match(reg);
    if (r != null) {
      return r[1];
    }
    return null;
  }),
}));
jest.mock("@teld/api-proxy/src/utils/cookie", () => ({
  createCookie: jest.fn((param) => {
    if (param == "teld_locale") {
      return "zh-CN";
    }
  }),
  readCookie: jest.fn(),
  eraseCookie: jest.fn(),
}));
jest.mock("@teld/api-proxy/src/utils/application.js", () => ({
  getAppSetting: jest.fn(() => {
    return {
      appCode: "web",
      isRemind: false,
      CuntomNginxSG: "//sgi.teld.cc:7777",
      ProductVersionType: "Teld",
      UseGaoDeMap: false,
      UseGaoDeMapUI: false,
      LoadContainerSdk: true,
      customHeaderMeta: {
        css: [
          {
            href: "//resource.teld.cn/fas/fas-icons.css",
          },
          {
            href: "//resource.teld.cn/fas/dx.light.css",
          },
        ],
        script: [],
      },
      WX_APPID: {
        web: "wxd1cbe7a8806bda75",
      },
      Alipay_APPID: {
        web: {
          cs: "wxd1cbe7a8806bda75",
          sm: "wxd1cbe7a8806bda75",
        },
        ecms: "XXXXXXXXXXXXXX",
      },
      Dingtalk_APPID: "87023559",
      IsStandardEnv: false,
      ViewModule: 2,
      UseChart: false,
      LoadAllComponent: true,
    };
  }),
}));

jest.mock("@teld/api-proxy/src/utils/ajax.js", () => ({
  getDataAsync: jest.fn((param) => {
    if (!param.url) {
      return Promise.resolve({
        data: { state: 1, data: [] },
      });
    }
    if (param.url == "WRP-Runtime-GetAppSystemCategoriesDetail") {
      return Promise.resolve({
        data: { state: 1, data: [] },
      });
    }
    if (param.url == "WRP-Runtime-GetUserProfile") {
      return Promise.resolve({
        data: { state: 1, data: [] },
      });
    }
    if (param.url == "CMS-GetStaInfo") {
      return Promise.resolve({
        data: {
          data: {
            Power: 14455.69,
          },
          state: "1",
        },
      });
    }
    if (param.url == "WRP-Runtime-GetTenantConfigByURL&tenantDomain=localhost.teld.cc") {
      return Promise.resolve({
        data: {
          data: null,
          state: "1",
        },
      });
    }
    // 返回0表示菜单不存在 1表示用户无权限 2表示用户有权限
    if (param.url == "SYSSrv-ValidUserMenuByUrl") {
      const parsedData = JSON.parse(param.data.param);
      if (parsedData.MId == "nopower") {
        //处理用户无权限的情况...
        return Promise.resolve({
          data: { state: 1, data: 1 },
        });
      }
      if (parsedData.MId == "nofunc") {
        //处理用户无权限的情况...
        return Promise.resolve({
          data: { state: 1, data: 0 },
        });
      }
      if (parsedData.MId == "normal") {
        //处理用户无权限的情况...
        return Promise.resolve({
          data: { state: 1, data: 2 },
        });
      }

      return Promise.resolve({
        data: { state: 1, data: 2 },
      });
    }
  }),
  getSession: jest.fn(() => {
    return Promise.resolve({
      CustInfomationVMSG: {
        customerID: "76aa7c3b-999f-41bf-9fe8-57fae921b0e3",
        userID: "e0a78136-058a-40e2-bab4-70d87422465b",
        skin: null,
        headImg: "http://resource.teld.cc/teldimage/101/cf71e6941b2742489434edb32243a823.png",
        realname: "侯加奇",
        alias: "侯加奇haaa",
        gender: null,
        mobile: "18686925935",
        birthday: "2022-07-15",
        recordOfFormalSchoolingID: null,
        recordOfFormalSchoolingValue: null,
        occuopationTypeID: null,
        occuopationID: null,
        occuopationValue: null,
        incomeID: null,
        incomeValue: null,
        liveCityID: null,
        liveCityValue: null,
        updatekbn: null,
        deliveryAddress: {
          provinceCode: null,
          provinceValue: null,
          cityCode: null,
          cityValue: null,
          districtCode: null,
          districtValue: null,
          otherAddress: null,
          mobile: null,
          receiver: null,
        },
      },
      CurUserForWebUI: {
        UserId: "e0a78136-058a-40e2-bab4-70d87422465b",
        Account: "18686925935",
        UserName: "侯加奇",
        Alias: null,
        Skin: null,
        Avatar: null,
        Mobile: "18686925935",
        EMail: "houjq@teld.cn",
        CompanyId: "b0ba1259-54cc-4122-b66e-41988ac531ef",
        DepartmentId: "0c0b4f96-8d6e-40f9-8b12-ab39972bd7d3",
        WorkGroupId: "7d637ca3-a253-40dd-85a6-c5bda2f52d65",
        CustomerID: "76aa7c3b-999f-41bf-9fe8-57fae921b0e3",
        Gender: null,
        BusiCustID: "",
        ACCompanyID: "fb247fb4-13d1-4c1b-acf8-27278b9bd0b1",
        CompanyName: "集团总部",
        DepartmentName: "云平台中心",
        WorkGroupName: "平台智能保障部",
        BirthDay: "",
        AreaCode: "86",
      },
    });
  }),
}));
